package cn.edu.athcm.bean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class TestList {

    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("apple");
        list.add("pear");
        list.add("orange");
        System.out.println(list);
        //遍历1
        System.out.println("=====1=======");
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
        //遍历2
        System.out.println("=====2=======");
        for(String s: list){
            System.out.println(s);
        }
        //遍历3
        System.out.println("=====3=======");
        Iterator<String> it = list.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }
        //遍历4
        System.out.println("=====4=======");
        list.forEach(System.out::println);
        //通过Collections的静态方法操作list
        Collections.sort(list);
        System.out.println(list);
    }

}
